package com.sample.camerax.ui.home

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.loyal.camerax.R
import com.loyal.camerax.ui.CameraActivity
import com.loyal.camerax.ui.LifecycleCameraActivity
import com.loyal.camerax.ui.camera.CameraFragmentActivity
import com.loyal.camerax.ui.settings.CameraSettingsActivity
import com.loyal.camerax.utils.PreferenceHelper
import com.sample.camerax.databinding.FragmentSplashBinding
import com.sample.camerax.ui.QrCodeActivity
import com.sample.camerax.ui.SampleCameraActivity
import com.sample.camerax.ui.VideoActivity

class SplashFragment : Fragment() {

    private var _binding: FragmentSplashBinding? = null
    private val binding get() = _binding!!

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View {
        _binding = FragmentSplashBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val activity = activity ?: return
        binding.btnTest.setOnClickListener {
            CameraSettingsActivity.launch(activity, null, R.id.settings_fragment)
        }
        binding.btnPreview.setOnClickListener {
            val intent = Intent(activity, SampleCameraActivity::class.java)
            startActivity(intent)
        }
        binding.btnGallery.setOnClickListener {
            CameraSettingsActivity.launch(activity, null, R.id.gallery_fragment)
        }

        //Activity
        binding.btnLife.setOnClickListener {
            val intent = Intent(activity, LifecycleCameraActivity::class.java)
            startActivity(intent)
        }
        binding.btnBase.setOnClickListener {
            val intent = Intent(activity, CameraActivity::class.java)
                .putExtra(PreferenceHelper.MUTABLE_ORIENTATION, true)
            startActivity(intent)
        }

        //Fragment
        binding.btnLifeFragment.setOnClickListener {
            CameraFragmentActivity.launch(activity, cameraIdRes = R.id.lifecycle_fragment)
        }
        binding.btnBaseFrag.setOnClickListener {
            CameraFragmentActivity.launch(activity, true, R.id.camera_fragment)
        }


        binding.btnRecord.setOnClickListener {
            val intent = Intent(activity, VideoActivity::class.java)
            startActivity(intent)
        }
        binding.btnScan.setOnClickListener {
            val intent = Intent(activity, QrCodeActivity::class.java)
            startActivity(intent)
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }
}